package com.aiti.lulian.gxmh.service.impl;

import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.gxmh.dto.GxmhMessageUserDto;
import com.aiti.lulian.gxmh.entity.GxmhMessage;
import com.aiti.lulian.gxmh.entity.GxmhMessageUser;
import com.aiti.lulian.gxmh.service.IGxmhMessageUserService;
import com.aiti.lulian.gxmh.vo.GxmhMessageUserVo;
import com.aiti.lulian.mapper.gxmh.GxmhMessageUserMapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class GxmhMessageUserServiceImpl extends BaseSerivceImpl<GxmhMessageUserMapper, GxmhMessageUser> implements IGxmhMessageUserService {

    @Autowired
    private GxmhMessageUserMapper gxmhMessageUserMapper;

    @Override
    public List<GxmhMessageUserVo> getMyMessageList(Page<GxmhMessage> page, GxmhMessageUserDto dto) {
        return gxmhMessageUserMapper.selectMyMessageList(page, dto);
    }

    @Override
    public Integer getUnreadCount(String userId) {
        return gxmhMessageUserMapper.selectUnreadCount(userId);
    }

    @Override
    public Message readMessage(GxmhMessageUserDto dto) {
        this.update(new LambdaUpdateWrapper<GxmhMessageUser>().eq(GxmhMessageUser::getUserId, dto.getUserId()).eq(GxmhMessageUser::getMessageId, dto.getMessageId()).set(GxmhMessageUser::getIsRead, 1).set(GxmhMessageUser::getReadTime, new Date()));
        return Message.success();
    }

    @Override
    public GxmhMessageUserVo getMyMessageDetails(String userId, String messageId) {
        return gxmhMessageUserMapper.selectMyMessageDetails(userId, messageId);
    }
}
